<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.ResultSet" %>
<%--
  Created by IntelliJ IDEA.
  User: 29904
  Date: 2024/9/23
  Time: 11:10
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% String id=request.getParameter("stuid");%>
<%@page import="java.sql" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>条件查询</title>
    <%
    ResultSet rs; //数据库查询结果集对象
    %>
    <%
        String dbName = "jbdc";//数据库名称
        String userName = "root";//账号
        String userPasswd = "123456";//
        String url = "jbdc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
        Class.forName("com.mysql.cj.jdbc.Driver");//8.0带.cj5.7以下不带
        Connection conn = DriverManager.getConnection(url);//链接数据库
        Statement statement = conn.createStatement();
        String sql = "select * from student where id="+id;
        rs = statement.executeQuery(sql);
    %>
</head>
<body>
<table border="1">
    <th colspan="4" style="font-size: x-large;alignment: center">学生信息表</th>
    <tr style="text-align: center">
        <td>学号</td>
        <td>姓名</td>
        <td>出生日期</td>
        <td>所在班级</td>
    </tr>
    <%-- 循环查询结果--%>
        <% while (rs.next()){%>
    <%--使用表达式显示结果集中对应的列值 --%>

    <tr style="text-align: center;">
        <td><%=rs.getString(1)%></td>
        <td><%=rs.getString(2)%></td>
        <td><%=rs.getString(3)%></td>
        <td><%=rs.getString(4)%></td>
    </tr>
        <%}%>
        <%
        rs.close();
        statement.close();
        conn.close();
    %>
</body>
</html>
